package com.zzx.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zzx.common.DataSource;
import com.zzx.common.DataSourcesType;
import com.zzx.common.DynamicDataSourceHolder;
import com.zzx.mapper.UserMapper;
import com.zzx.model.User;
import com.zzx.service.IUserService;

@Service
public class UserServiceImpl implements IUserService{

	@Autowired
	private UserMapper userMapper;
	
	@DataSource(name=DataSourcesType.DB2)
	@Override
	public void save(User user) {
		userMapper.save(user);
		
	}

	@DataSource(name=DataSourcesType.DB2)
	@Override
	public void update(User user) {
		userMapper.update(user);
	}

	@DataSource(name=DataSourcesType.DB2)
	@Override
	public void deleteById(Integer id) {
		userMapper.deleteById(id);
	}

	@DataSource(name=DataSourcesType.DB2)
	@Override
	public User getById(Integer id) {
		System.out.println("**数据源22:"+DynamicDataSourceHolder.getDataSouce());
		DynamicDataSourceHolder.putDataSource(DataSourcesType.DB2.name());
		return userMapper.getById(id);
	}

	@DataSource(name=DataSourcesType.DB2)
	@Override
	public List<User> findAll(Map<String, String> params) {
		
		return userMapper.findAll(params);
	}

	@DataSource(name=DataSourcesType.DB2)
	@Override
	public int getCount(Map<String, String> params) {
		
		return userMapper.getCount(params);
	}

}
